#pragma once
#include <mydll.h>
#include <mythread.hxx>
#include <vector>

class TaskManager;
class RobotManager;
class DB;
class GisusDB;
class Task;
class User;
class FileLog;

typedef void(*DMFun)(std::string,int);

extern DMFun g_DMFun;
void g_DisplayMsg(std::string msg, int msgType);
class EXPORT Auto : public Thread
{
public:
	Auto(DMFun f=0);
	~Auto();

	int Login(const string& username, const string& pwd);
	void Shutdown(void);

	/* use in pair for user to input Captcha. */
	const char* GetCaptcha(size_t& size, bool& urgent);
	bool SetCaptcha(const string& captcha);

	/* task related methods. */
	int SaveTask(Task* task);

	void SetQueryInterval(int interval);
	void SetHotQueryInterval(int interval);

	void DisplayMsg(string msg, int msgType);

	void StartQuery(bool start = true);
	void StartHotQuery(bool start = true);

	/* Task browse */
	Task* GetTaskByCjh(const string& cjh);
	Task* GetNeighbor(int curTaskId, bool next=true);
	bool DeleteTask(const string& cjh);

	const Task* SetPTask(const string& cjh);
	bool RestoreBEndData(void);

	const User* GetUser(void) const {return user;}

	void Scan(bool thorough = false);

protected:
	virtual void Execute(Arg arg);
private:
	const User* user;
	RobotManager* robotManager;
	TaskManager* taskManager;
	DB* db;
	GisusDB* gisusdb;
	bool isShutdownRequested;
	FileLog* _filelog;

	bool BeMute(const Task* task) const;
};